package com.haitonghop.requester;

import org.json.JSONObject;

import android.util.Log;

import com.haitonghop.modules.news.News;
import com.haitonghop.modules.news.RSS;
import com.haitonghop.modules.news.rssreader.SimpleFeedReader;
import com.haitonghop.modules.news.rssreader.model.Feed;
import com.haitonghop.network.Request;
import com.haitonghop.network.RequestListener;

public class RssRequester extends Request {

	private RequestListener requestListener;
	public RSS item;
	public News news;
	public Feed feed;

	public RssRequester(News news, RSS item, RequestListener listener) {
		this.requestListener = listener;
		this.news = news;
		this.item = item;
	}

	@Override
	public void cancelRequest() {
		// TODO Auto-generated method stub
	}

	@Override
	public void runRequest() {
		Log.i("requestFinished", "runRequest");
		SimpleFeedReader feedReader = new SimpleFeedReader();
		feed = feedReader.getFeed(item.getLink());
		Log.i("requestFinished", "runRequest");

		requestFinished(null);
	}

	@Override
	public void requestFinished(JSONObject jsonObject) {
		if (requestListener != null) {
			requestListener.onRequestComplete(this);
		}
	}

	@Override
	public void requestFailed(int errorCode, String message) {

	}
}
